<!DOCTYPE html>
<html lang="zh-cmn-Hans-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>定时更新的广告栏</title>
    <style>
        #app {
            text-align: center;
            padding: 50px;
            margin: 20px auto;
            width: 600px;
        }

        .banner {
            width: 495px;
            height: 212px;
            line-height: 212px;
            box-shadow: 5px 5px 10px #888888;
            background-color: #033592;
            margin: 0 auto;
            border-radius: 20px;
            background-size:495px 212px;
        }
    </style>
</head>
<body>
<div id="app">
    <div :style="imageUrl" :class="bannerClass"></div>
</div>
<script src="./js/vue.min.js"></script>
<script>
    var vm = new Vue({
        el: "#app",
        data: {
            index:0,
            imageUrl:{
                "background-image":"url(./img/banner1.jpg)"
            },
            bannerClass:{
                banner:true
            }
        },
        mounted:function () {
            var _this=this;
            this.timer=setInterval(function () {
                _this.imageUrl={
                    backgroundImage:"url(./img/banner"+(_this.index%4+1)+".jpg)",
                    transition:"all 1.5s 0s"
                };
                _this.index++;
            },3000);
        },
        beforeDestroy:function () {
            if (this.timer){
                clearInterval(this.timer);
            }
        }
    });
</script>
</body>
</html>
